package code.example.base.data.struct.sort;

import code.example.tool.LogFactory;

import java.util.Arrays;

/**
 * 冒泡排序
 */
public class BubbleSort implements  Sorter{
    private void print(int [] data){

        String str = Arrays.toString(data);
        LogFactory.getLog().info(str);
    }
    public void sort(int [] data){
        for(int i =0;i <data.length;i++) {
            for (int j = 1; j < data.length-i; j++) {
                int cur = j - 1;
                if (data[cur] > data[j]) {
                    int  temp = data[j];
                    data[j] = data[cur];
                    data[cur] = temp;
                }
            }
        }
      /*  int temp = 0;
        for(int i=0;i<data.length;i++){
            for(int j=i+1;j<data.length;j++){
                if(data[i] > data[j]){
                    temp = data [i];
                    data [i] = data[j];
                    data [j] = temp;
                }
            }
        }*/
    }
}
